package com.edu.employee.config;

import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ProjectName: summer-project
 * @Titile: AvatarMappingConfig
 * @Author: Lucky
 * @Description: 头像映射配置类
 */
@SpringBootConfiguration
public class AvatarMappingConfig implements WebMvcConfigurer {
    //注入头像保存的目录
    @Setter //setter注入
    @Value("${avatar.path}")
    private String saveDir;
    // alt+insert

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 使用浏览器访问 http://localhost:8080/abc.png
        //那么就会去C:\Users\Lucky\avatar\这个目录下去找abc.png
        registry.addResourceHandler("/**")//映射的url
                .addResourceLocations("file:///"+saveDir);//定位的资源目录位置
    }
}
